package Tela;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;

public class ItemPGArco extends ItemPanelGrafo {
	// Rodrigo Sestari - Desenha Flexa
	public static final int DEFAULT_LINE_WIDTH = 1;

	public static final int DEFAULT_HEAD_LENGTH = 10;

	public static final int DEFAULT_HEAD_WIDTH = 8;

	private float lineWidth = DEFAULT_LINE_WIDTH;

	private float headLength = DEFAULT_HEAD_LENGTH;

	private float headWidth = DEFAULT_HEAD_WIDTH;

	protected Point2D.Float p1;

	protected Point2D.Float p2;
	Polygon arrow;

	private ItemPGNoh nohInicial;
	private ItemPGNoh nohFinal;

	public ItemPGNoh getNohInicial() {
		return nohInicial;
	}

	public ItemPGNoh getNohFinal() {
		return nohFinal;
	}

	public ItemPGArco(ItemPGNoh nohInicial) {
		this.nohInicial = nohInicial;
	}

	public void setNohFinal(ItemPGNoh nohFinal) {
		this.nohFinal = nohFinal;
	}

	public void desenhar(Graphics g, int x, int y, boolean selecionado) {

		if (nohFinal != null) {
			x = nohFinal.getX();
			y = nohFinal.getY();
		}
		g.setColor(Color.black);
		// Rodrigo Sestari - Desenha Flexa
		g
				.drawPolygon(Flecha(nohInicial.getX(), nohInicial.getY(),
						x - 5, y - 5));
	}

	// Rodrigo Sestari - Desenha Flexa
	private Polygon Flecha(int X1, int Y1, int X2, int Y2) {

		return desenhaFlecha(new Point2D.Float(X1, Y1), new Point2D.Float(X2,
				Y2), DEFAULT_LINE_WIDTH, DEFAULT_HEAD_LENGTH,
				DEFAULT_HEAD_WIDTH);

	}

	// Rodrigo Sestari - Desenha Flexa
	private Polygon desenhaFlecha(Point2D.Float p1, Point2D.Float p2,
			float lineWidth, float headLength, float headWidth) {
		this.p1 = p1;
		this.p2 = p2;
		this.lineWidth = lineWidth;
		this.headLength = headLength;
		this.headWidth = headWidth;

		float x, s3X;
		float y, s3Y;
		float sin = (p2.y - p1.y) / (float) p1.distance(p2);
		float cos = (p2.x - p1.x) / (float) p1.distance(p2);

		arrow = new Polygon();
		x = p1.x + (sin * lineWidth / 2);
		y = p1.y - (cos * lineWidth / 2);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		s3X = p2.x - headLength * cos;
		s3Y = p2.y - headLength * sin;

		x = s3X + (sin * lineWidth / 2);
		y = s3Y - (cos * lineWidth / 2);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		x = s3X + (headWidth / 2 * sin);
		y = s3Y - (headWidth / 2 * cos);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		arrow.addPoint((int) Math.round(p2.x), (int) Math.round(p2.y));

		x = s3X - (headWidth / 2 * sin);
		y = s3Y + (headWidth / 2 * cos);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		x = s3X - (sin * lineWidth / 2);
		y = s3Y + (cos * lineWidth / 2);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		x = p1.x - (sin * lineWidth / 2);
		y = p1.y + (cos * lineWidth / 2);
		arrow.addPoint((int) Math.round(x), (int) Math.round(y));

		return arrow;
	}

	public boolean contido(int x, int y) {
		return false; // nao consegue selecionar um arco

	}

	public void deslocar(int x, int y) {
	}

	public int getPosX() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getPosY() {
		// TODO Auto-generated method stub
		return 0;
	}

	public String getTextoObjeto() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void SetSql(String sql) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getSql() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<String> getSelecoes() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setSelecoes(String Condicao) {
		// TODO Auto-generated method stub

	}

	@Override
	public HashMap<String, String> getRestricoes() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setRestricoes(HashMap<String, String> restricoes) {
		// TODO Auto-generated method stub

	}
}